#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2021/12/28 17:13
    Desc  :
--------------------------------------
"""
from functools import wraps

from common.utils.log_utils import logger
from extends.microseer.login.login import moa_login

global HEADERS
global ENV
global MSCID

HEADERS = dict()
ENV = 'pre'
MSCID = '288572'


def login_auth_moa(env=ENV, mscid=MSCID):
    """
    登陆装饰器
    :param env: 登陆环境
    :return:
    """

    def view_decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            logger.info(get_env())
            token = moa_login(env = get_env(), mscid = get_mscid())
            headers = dict(Authorization = f'Bearer {token}', Mscid = f'{mscid}')
            set_headers(headers = headers)
            return func(*args, **kwargs)

        return wrapper

    return view_decorator


def set_headers(headers: dict):
    global HEADERS
    HEADERS = headers
    return HEADERS


def get_headers():
    return HEADERS


def set_env(env):
    global ENV
    ENV = env
    return ENV


def get_env():
    return ENV


def set_mscid(mscid):
    global MSCID
    MSCID = mscid
    return MSCID


def get_mscid():
    return MSCID
